package com.usian.controller;

import com.usian.AdNode;
import com.usian.PageResult;
import com.usian.pojo.TbContent;
import com.usian.pojo.TbContentCategory;
import com.usian.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ContentController {

    @Autowired
    private ContentService contentService;

    /**
     * 内容分类管理根据父节点查询子节点
     *
     * @param id
     * @return
     */
    @RequestMapping("selectContentCategoryByParentId")
    public List<TbContentCategory> selectContentCategoryByParentId(@RequestParam Long id){
        return contentService.selectContentCategoryByParentId(id);
    }

    /**
     * 添加内容分类管理数据
     *
     * @param parentId
     * @param name
     * @return
     */
    @RequestMapping("insertContentCategory")
    public Integer insertContentCategory(@RequestParam Long parentId,@RequestParam String name ){
        return contentService.insertContentCategory(parentId,name);
    }

    /**
     * 删除内容分类管理数据
     *
     * @param categoryId
     * @return
     */
    @RequestMapping("deleteContentCategoryById")
    public Integer deleteContentCategoryById(@RequestParam Long categoryId){
        return contentService.deleteContentCategoryById(categoryId);
    }

    /**
     * 修改内容分类数据
     *
     * @param id
     * @param name
     * @return
     */
    @RequestMapping("updateContentCategory")
    public Integer updateContentCategory(@RequestParam Long id,@RequestParam String name){
        return contentService.updateContentCategory(id,name);
    }

    /**
     * 根据分类id查询内容列表
     *
     * @param categoryId
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("selectTbContentAllByCategoryId")
    public PageResult selectTbContentAllByCategoryId(@RequestParam Long categoryId,
                                                     @RequestParam Integer page,
                                                     @RequestParam Integer rows){
        return contentService.selectTbContentAllByCategoryId(categoryId,page,rows);
    }

    /**
     * 增加分类内容
     *
     * @param tbContent
     * @return
     */
    @RequestMapping("insertTbContent")
    public Integer insertTbContent(@RequestBody TbContent tbContent){
        return contentService.insertTbContent(tbContent);
    }

    /**
     * 删除分类内容
     *
     * @param ids
     * @return
     */
    @RequestMapping("deleteContentByIds")
    public Integer deleteContentByIds(@RequestParam Long ids){
        return contentService.deleteContentByIds(ids);
    }

    /**
     * 查询首页大广告位
     *
     * @return
     */
    @RequestMapping("selectFrontendContentByAD")
    public List<AdNode> selectFrontendContentByAD(){
        return contentService.selectFrontendContentByAD();
    }
}
